﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using mIRCx.IRC.Client.Engine;
using mIRCx.IRC.Client.Engine.Data;

using PluginInterface;

namespace CSharpIrcBot.Module.Greetings
{
    public class Greetings : IPlugin
    {
        public Greetings( )
        {
        }

        #region Plugin Required Information
        string myName = "Greetings";
        string myDescription = "This module greets users as they enter the channel";
        string myVersion = "1.0.1";
        string myAuthor = "Macros";
        IPluginHost myHost = null;
        IrcClient myIrcClient = null;

        public string Description
        {
            get { return myDescription; }
        }

        public string Name
        {
            get { return myName; }
        }

        public string Version
        {
            get { return myVersion; }
        }

        public string Author
        {
            get { return myAuthor; }
        }

        public IPluginHost Host
        {
            get
            {
                return myHost;
            }
            set
            {
                myHost = value;
                myIrcClient = myHost.IrcClient;
            }
        }

        public void Initialize()
        {
            myIrcClient.OnJoin += new JoinHandler( ircClient_OnJoin );
        }

        public void Dispose()
        {
            myIrcClient.OnJoin -= new JoinHandler( ircClient_OnJoin );
        }
        #endregion

        #region Protected Members
        protected 

        #endregion

        void ircClient_OnJoin( string userName, string channel )
        {
            if( myIrcClient.ServerInfo.NickName != userName )
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat( "Hey there \u0002{0}\u0002, welcome to {1}.", userName, channel );
                myIrcClient.SendServerData( "PRIVMSG " + channel + " :" + msg );
            }
        }
    }
}
